<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;

/**
 * 微信二维码用途表
 * @package App\Models
 */
class WxQrcodeUse extends Model
{
    use SoftDeletes;
    //主键
    protected $primaryKey = 'id';
    protected $dateFormat = 'Y-m-d H:i:s';

    /**
     * 二维码模型关联
     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
     */
    public function qrcode()
    {
        return $this->belongsTo('App\Models\WxQrcode','qrcode_id','qrcode_id');
    }

    /**
     * 分组访问器
     * @return string
     */
    public function getGroupAttribute()
    {
        $groupId = $this->group_id ?? 0;
        $groupData = (new \App\Services\WxQrcode\WxQrcodeGroupService())->getGroupDataById($groupId);
        return $groupData;
    }
}
